<%@ taglib uri="http://java.sun.com/portlet" prefix="portlet" %>
<%@ taglib uri="http://java.sun.com/jstl/core" prefix="c" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<fmt:setBundle basename="labels"/>

<jsp:include flush="true" page="header.jsp" />
<jsp:include flush="true" page="calendar.jsp" />
<jsp:include flush="true" page="validation.jsp" />

<!-- browse -->
<form action="<portlet:actionURL />">
	<input type="submit" value="<fmt:message key="label.back"/>" class="crud">
</form>
<!-- edit form -->
<form name="editForm" 
	action="<portlet:actionURL />" 
	onSubmit="return validateEditForm(this);">
	<input type="hidden" name="action" value="PERSIST"/> 
	<c:if test="${bean.newBean}">
		<input type="hidden" name="newBean" value="true"/> 
	</c:if>
<table width="100%" class="crud">
<c:forEach var="field" items="${bean.fields}">
    <c:choose>
        <c:when test="${field.def.id && not empty field.value}">
		<tr>
			<td class="even" width="10%">
				<c:out value="${field.def.label}"/>
			</td>
			<td>
        	<input type="hidden" 
	        	name="<c:out value="${field.def.name}"/>"
	        	value="<c:out value="${field.value}"/>"/>
			<c:out value="${field.value}"/>
			</td>
		</tr>
        </c:when>

        <c:otherwise>
		<c:if test="${!field.def.generatedValue}">
		<c:if test="${!field.def.hidden}">
		<c:if test="${(!field.def.newDisabled && bean.newBean) || !bean.newBean}">
		<tr>
			<td class="even" width="10%">
				<c:out value="${field.def.label}"/>
			</td>
			<td>
<c:choose>
	<c:when test="${field.def.editDisabled && !bean.newBean}">
		<c:out value="${field.value}"/>
	</c:when>
	<c:otherwise>
		<c:set var="field" value="${field}" scope="request" />
		<c:set var="editor" value="editor/${field.def.editor}" scope="page" />
		<jsp:include page="<%= (String) pageContext.getAttribute("editor") %>"/>
	</c:otherwise>
</c:choose>
			</td>
		</tr>
		</c:if>	
		</c:if>
		</c:if>
        </c:otherwise>
    </c:choose>		
</c:forEach>
</table>
	<input 
		type="submit" 
		value="<fmt:message key="label.save"/>" 
		class="crud"/>
</form>

